package com.ugoodtech.mdcc.core.domain;

/* Copyright (C) Ugoodtech, Inc - All Rights Reserved.
 * Unauthorized copying of this file, via any medium is strictly prohibited.
 * Proprietary and confidential.
 * Written by Stone Shaw.
 */

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.ugoodtech.mdcc.core.domain.converter.GenderConverter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.List;

@ApiModel("用户详情模型")
@Entity
@Table(name = "user_profiles")
public class UserProfile extends BaseEntity {
    @ApiModelProperty("登陆信息")
    private User user;
    @ApiModelProperty("编号")
    private String serialNumber;
    @ApiModelProperty("姓名")
    private String realName;
    @ApiModelProperty("手机号")
    private String mobilePhone;
    @ApiModelProperty("所属部门")
    private List<Department> departmentList;
    @ApiModelProperty("负责的省份")
    private List<Nation> nationList;
    @ApiModelProperty("负责的品牌")
    private List<Brand> brandList;
    @ApiModelProperty("经销商绑定的维修站")
    private List<Station> stationList;

    //////////////////////////////////////////////

    @ApiModelProperty("性别 0 男，1 女，2 未知")
    private Gender gender;
    @ApiModelProperty("头像")
    private String avatar;
    @ApiModelProperty("公司")
    private String company;
    @ApiModelProperty("等级")
    private String level;
    @ApiModelProperty("职务")
    private String position;
    @ApiModelProperty("邮箱")
    private String email;
    @ApiModelProperty("座机")
    private String telephone;
    @ApiModelProperty("所属部门")
    private Department department;
    @ApiModelProperty("所属技术部门")
    private Department technologyDeparment;
    @ApiModelProperty("所属销售")
    private UserProfile parentSale;
    @ApiModelProperty("经销商关联的技术人员")
    private UserProfile technologyUser;
    @ApiModelProperty("负责省份与产品")
    private String proincesAndBrands;
    @ApiModelProperty("执行添加操作的管理员")
    private UserProfile addUser;
    @ApiModelProperty("昵称")
    private String nickname;
    @ApiModelProperty("是否是管理员")
    private boolean isAdmin = false;

    @Column(name = "user_id", insertable = false, updatable = false)
    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    private Long userId;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinTable(
            name = "user_profile_deparment",
            joinColumns = {@JoinColumn(name = "user_profile_id")},
            inverseJoinColumns = @JoinColumn(name = "nation_id")
    )
    public List<Nation> getNationList() {
        return nationList;
    }

    public void setNationList(List<Nation> nationList) {
        this.nationList = nationList;
    }

    @JsonIgnore
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id")
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(length = 50)
    public String getMobilePhone() {
        return mobilePhone;
    }

    public void setMobilePhone(String mobilePhone) {
        this.mobilePhone = mobilePhone;
    }

    public String getSerialNumber() {
        return serialNumber;
    }

    public void setSerialNumber(String serialNumber) {
        this.serialNumber = serialNumber;
    }

    //
    @Column(length = 100)
    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    @Column(length = 100)
    public String getRealName() {
        return realName;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    @Column
    @Convert(converter = GenderConverter.class)
    public Gender getGender() {
        return gender;
    }

    public void setGender(Gender gender) {
        this.gender = gender;
    }

    @Column(length = 50)
    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }


    @Column(length = 100)
    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public String getLevel() {
        return level;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }


    @ManyToOne
    @JoinColumn(name = "deparment_id")
    public Department getDepartment() {
        return department;
    }

    public void setDepartment(Department department) {
        this.department = department;
    }

    @ManyToOne
    @JoinColumn(name = "technology_deparment_id")
    public Department getTechnologyDeparment() {
        return technologyDeparment;
    }

    public void setTechnologyDeparment(Department technologyDeparment) {
        this.technologyDeparment = technologyDeparment;
    }

    @ManyToOne
    @JoinColumn(name = "parent_sale_id")
    public UserProfile getParentSale() {
        return parentSale;
    }

    public void setParentSale(UserProfile parentSale) {
        this.parentSale = parentSale;
    }


    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinTable(
            name = "user_stations",
            joinColumns = {@JoinColumn(name = "profile_id")},
            inverseJoinColumns = @JoinColumn(name = "station_id")
    )
    public List<Station> getStationList() {
        return stationList;
    }

    public void setStationList(List<Station> stationList) {
        this.stationList = stationList;
    }

    @ManyToOne
    @JoinColumn(name = "technology_profile_id")
    public UserProfile getTechnologyUser() {
        return technologyUser;
    }

    public void setTechnologyUser(UserProfile technologyUser) {
        this.technologyUser = technologyUser;
    }

    @Column(name = "proince_brand")
    public String getProincesAndBrands() {
        return proincesAndBrands;
    }

    public void setProincesAndBrands(String proincesAndBrands) {
        this.proincesAndBrands = proincesAndBrands;
    }

    @ManyToOne
    @JoinColumn(name = "add_profile_id")
    public UserProfile getAddUser() {
        return addUser;
    }

    public void setAddUser(UserProfile addUser) {
        this.addUser = addUser;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinTable(
            name = "user_department",
            joinColumns = {@JoinColumn(name = "profile_id")},
            inverseJoinColumns = @JoinColumn(name = "department_id")
    )
    public List<Department> getDepartmentList() {
        return departmentList;
    }

    public void setDepartmentList(List<Department> departmentList) {
        this.departmentList = departmentList;
    }

    @ManyToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @JoinTable(
            name = "user_brand",
            joinColumns = {@JoinColumn(name = "profile_id")},
            inverseJoinColumns = @JoinColumn(name = "brand_id")
    )
    public List<Brand> getBrandList() {
        return brandList;
    }

    public void setBrandList(List<Brand> brandList) {
        this.brandList = brandList;
    }

    @Column(name = "is_admin")
    public boolean isAdmin() {
        return isAdmin;
    }

    public void setAdmin(boolean admin) {
        isAdmin = admin;
    }
}
